/**
 * 会员管理路由
 * @module routes/membership
 */

const express = require('express');
const router = express.Router();
const membershipController = require('../controllers/membership.controller');
const authMiddleware = require('../middlewares/auth.middleware');
const validation = require('../middlewares/validation.middleware');

// 所有路由都需要身份验证
router.use(authMiddleware.authenticate);

// 获取所有会员计划（公开）
router.get('/plans', membershipController.getAllPlans);

// 获取用户会员状态
router.get('/status', membershipController.getUserMembershipStatus);

// 升级到专业版
router.post('/upgrade', validation.validateUpgrade, membershipController.upgradeToPro);

// 取消专业版
router.post('/cancel', membershipController.cancelPro);

// 获取用户交易记录
router.get('/transactions', membershipController.getUserTransactions);

// === 管理员路由 ===
// 管理员: 获取所有交易记录
router.get('/admin/transactions', authMiddleware.requireAdmin, membershipController.getAllTransactions);

// 管理员: 更新会员计划
router.put('/admin/plans', authMiddleware.requireAdmin, validation.validatePlan, membershipController.updatePlan);

module.exports = router; 